/* Copyright (c) 2011 Timothée Lacroix
 * This file is part of HINAPT.
 *
 * HINAPT is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * HINAPT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HINAPT.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "filesystem.hpp"

namespace fs {


void listFiles(vector<path>& liste,path dossier){
    for(directory_iterator it(dossier);it!=end_iter;++it)
        if(is_regular_file(it->status())){
            liste.push_back(it->path());
        }
}

Mat extract(path path){
    Mat img=imread(path.string());
    cumulate(img);
    return img;
}

void load(vector<Mat>& pos,vector<Mat>&neg){
  pos.clear();
  neg.clear();
  vector<path> images;
  listFiles(images,initial_path()/"trainPic/faceTrain/");

  for(int i=0;i<(int)images.size();i++){
    pos.push_back(extract(images[i]));
  }
  images.clear();
  listFiles(images,initial_path()/"trainPic/nonfaceTrain/");
  for(int i=0;i<(int)images.size();i++){
    neg.push_back(extract(images[i]));
  }
  cout<<pos.size()<<" positive images loaded and "<<neg.size()<<
                    " negative images loaded"<<endl;
}

}
